<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title></title>
  <script src="./lib/vue.min.js"></script>
  <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
  <script src="./lib/elementui-index.js"></script>
  <script src="./lib/axios.min.js"></script>
  <script src="./lib/params.js"></script>
  <script src="./lib/token.js"></script>
</head>
<style>
  .c1{
    width: 30%;
    margin: 0 auto;
    align-content: center;
    margin-top: 10%;
  }
</style>
<body>
<div id="app" class="c1">
  <template>
    <el-form ref="form" :model="form" label-width="120px">

      <el-form-item label="姓名：">
        <el-input v-model="form.uname"></el-input>
      </el-form-item>


      <el-form-item label="密码：">
        <el-input type="password" v-model="form.upassword"></el-input>
      </el-form-item>

      <el-form-item label="注册时间：">
        <!-- <el-input v-model="form.utime"></el-input> -->
        <template>
          <div class="block" >
            <el-date-picker
              v-model="form.utime"
              type="datetime"
              placeholder="选择日期时间" 
              size="large"
              format="yyyy-MM-dd HH:mm:ss"
              value-format="yyyy-MM-dd HH:mm:ss">
            </el-date-picker>
          </div>
        </template>
      </el-form-item>

      <el-form-item label="密保问题：">
        <el-input v-model="form.usecurity"></el-input>
      </el-form-item>

      <el-form-item label="密保答案：">
        <el-input v-model="form.uanswer"></el-input>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit()">注册</el-button>
        <el-button typt="resetForm('onSubmit')">重置</el-button>
      </el-form-item>

    </el-form>
  </template>
</div>
<script>
  new Vue({
    el:"#app",
    data:{
      form: {
        uname: '',
        upassword: '',
        utime: '',
        usecurity:"您的身份证号码是多少？",
        uanswer:""
      }
    },
    methods:{
      onSubmit(){
        if(this.form.uname===""||this.form.utime===""||this.form.upassword===""||this.form.usecurity===""||this.form.uanswer===""){
          this.$message({
            showClose: true,
            message: '文本框不能为空！',
            type: 'warning'
          });
        }else {
          console.log(this.form)
          axios.post("http://localhost:8001/user/regist",this.form)
          .then(response=>{
            if(response.data.flag){
              this.$message({
                code:"20000",
                message: '注册成功!',
                type: 'success'
              });
              //location.href="login.html";
            }else {
              this.$message({
                showClose: true,
                message: '用户名已存在！',
                type: 'warning'
              });
            }
          })
        }
      },
    }
  })
</script>
</body>
</html>
